using System;
using NHibernate;

namespace Genrsis.Data.NHibernate
{
    public class NHibernateDataSession : IDataSession
    {
        private readonly ISession _session;

        public NHibernateDataSession(ISession session)
        {
            _session = session;
        }

        public IRepository<T> RepositoryFor<T>()
        {
            return new NHibernateRepository<T>(_session);
        }

        public void Save<T>(T item)
        {
            _session.SaveOrUpdate(item);
        }

        public void SubmitChanges()
        {
            _session.Flush();
        }

        public void Dispose()
        {
            // Only here to support using()...
        }
    }
}